package com.transino.bop.domain;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.kanas.framework.support.AbstractModel;

@XmlRootElement(name = "entity")
public class Entity extends AbstractModel implements Cloneable,Comparable<Entity> {

	private static final long serialVersionUID = 1L;
	
	private String id;
	private String name;
	private String label;
	private String labelProperty;
	private String categoryId;
	private String table;
	private String defaultShow;
	private Integer index;
	private String strPrimary;
	private Integer colspan;
	private Category superCategory;
	private String[] primary;
	private String[][] uniqueConstraints;
	private List<Property> properties;
	private List<PropertyGroup> groups;
	private String validator;

	@XmlAttribute(name = "id")
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}

	@XmlAttribute(name = "name")
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}

	@XmlAttribute(name = "categoryid")
	public String getCategoryId() {
		return categoryId;
	}
	
	public void setCategoryId(String categoryId) {
		this.categoryId = categoryId;
	}

	@XmlAttribute(name = "table")
	public String getTable() {
		return table;
	}
	
	public void setTable(String table) {
		this.table = table;
	}

	@XmlAttribute(name = "index")
	public Integer getIndex() {
		return index;
	}
	
	public void setIndex(Integer index) {
		this.index = index;
	}

	@XmlElement(name = "property")
	public List<Property> getProperties() {
		if(properties == null)properties = new ArrayList<Property>();
		return properties;
	}
	
	public void setProperties(List<Property> properties) {
		this.properties = properties;
	}

	@XmlElement(name = "group")
	public List<PropertyGroup> getGroups() {
		return groups;
	}

	public void setGroups(List<PropertyGroup> groups) {
		this.groups = groups;
	}

	public Category getSuperCategory() {
		return superCategory;
	}

	public void setSuperCategory(Category superCategory) {
		this.superCategory = superCategory;
	}

	@XmlAttribute(name = "defaultShow")
	public String getDefaultShow() {
		return defaultShow;
	}

	public void setDefaultShow(String defaultShow) {
		this.defaultShow = defaultShow;
	}

	public String[] getPrimary() {
		return primary;
	}

	public void setPrimary(String[] primary) {
		this.primary = primary;
	}

	@XmlElement(name = "primary")
	public String getStrPrimary() {
		return strPrimary;
	}

	public void setStrPrimary(String strPrimary) {
		this.strPrimary = strPrimary;
	}

	public String[][] getUniqueConstraints() {
		return uniqueConstraints;
	}

	public void setUniqueConstraints(String[][] uniqueConstraints) {
		this.uniqueConstraints = uniqueConstraints;
	}

	@XmlAttribute(name = "label")
	public String getLabel() {
		if(label == null) label = "";
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	@XmlAttribute(name = "labelProperty")
	public String getLabelProperty() {
		if(labelProperty == null) labelProperty = "id";
		return labelProperty;
	}

	public void setLabelProperty(String labelProperty) {
		this.labelProperty = labelProperty;
	}

	@XmlAttribute(name = "colspan")
	public Integer getColspan() {
		if(colspan==null)colspan = 2;
		return colspan;
	}

	public void setColspan(Integer colspan) {
		this.colspan = colspan;
	}

	public String getValidator() {
		if(validator == null) validator = "";
		return validator;
	}

	public void setValidator(String validator) {
		this.validator = validator;
	}

	@Override
	public String toIdString() {
		return this.id;
	}

	@Override
	public int compareTo(Entity o) {
		if(this.index==null || o.getIndex()==null) {
			return 1;
		}else {
			return this.index - o.getIndex();
		}
	}
	
}
